package com.jinsi.util;

import com.jinsi.service.ylt.UserSealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @ClassName UserSealTark
 * @Content  定时任务
 * @Author 姚龙腾
 * @Date 2022/10/12 11:53
 */
@Component
@EnableScheduling
@Slf4j
public class UserSealTark {
    @Autowired
    private UserSealService userSealService;

    /**
     * 每日下午5点发送请求查询用户封禁日期并进行解封
     */
    @Scheduled(cron = "0 10 17 * * ?")
    public void getSealIdList(){
        List<Integer> list = userSealService.getSealIdList();
        if (list.size() > 0){
            for (Integer i:list) {
                try {
                    log.info("解封用户定时任务开始执行  --今日解封的用户id：${}",list);
                    userSealService.upUserSeal(i,0);
                } catch (Exception e) {
                    log.error("解封用户定时任务出现异常  --报错原因：${}",e);
                }finally {
                    log.info("解封用户定时任务执行完毕  --今日解封的用户id：${}",list);
                }
            }
        }else {
            log.info("解封用户定时任务执行完毕  --今日没有达到解封日期的用户");
        }
    }

}
